//
//  HWQuestionsFooterView.m
//  HWExercises
//
//  Created by sxmaps_w on 2017/6/1.
//  Copyright © 2017年 wqb. All rights reserved.
//

#import "HWQuestionsFooterView.h"

@implementation HWQuestionsFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

    }
    
    return self;
}

- (void)setMark:(NSInteger)mark
{
    _mark = mark;
    
    if (mark == 0) {
        
        //上一题、下一题
        NSArray *titleArray = @[@"上一题", @"下一题"];
        for (int i = 0; i < titleArray.count; i++) {
            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.5 * i, 0, SCREEN_WIDTH * 0.5, 45)];
            btn.tag = i + 500;
            btn.backgroundColor = [UIColor whiteColor];
            btn.titleLabel.font = [UIFont systemFontOfSize:15.f];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateDisabled];
            [btn addTarget:self action:@selector(changeQuestionBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
        }
        
        //线
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 1) * 0.5, 6, 1, self.bounds.size.height-12)];
        //            if (i == 1) line.frame = CGRectMake(0, 0, self.bounds.size.width, 1);
        line.backgroundColor = [UIColor colorWithHexString:@"#efefef"];
        [self addSubview:line];
        
    }
    else {// 错题记录
        
        //上一题、下一题
        NSArray *titleArray = @[@"上一题", @"下一题"];
        for (int i = 0; i < titleArray.count; i++) {
            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(104 * i, 0, 104, 45)];
            btn.tag = i + 500;
            btn.backgroundColor = [UIColor whiteColor];
            btn.titleLabel.font = [UIFont systemFontOfSize:15.f];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateDisabled];
            [btn addTarget:self action:@selector(changeQuestionBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
            
            //线
            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(btn.jc_width-1, 6, 1, btn.jc_height-12)];
            //            if (i == 1) line.frame = CGRectMake(0, 0, self.bounds.size.width, 1);
            line.backgroundColor = [UIColor colorWithHexString:@"#efefef"];
            [btn addSubview:line];
        }
        
        UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(104 * 2, 0, kScreenWidth-104 * 2, 45)];
        btn1.tag = 502;
        btn1.backgroundColor = [UIColor whiteColor];
        btn1.titleLabel.font = [UIFont systemFontOfSize:15.f];
        [btn1 setTitle:@"我懂了" forState:UIControlStateNormal];
        [btn1 setTitleColor:[UIColor colorWithHexString:@"#0D61E5"] forState:UIControlStateNormal];
        [btn1 addTarget:self action:@selector(btn1Click) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn1];
    }
}

- (void)btn1Click
{
    if (_delegate && [_delegate respondsToSelector:@selector(getIt)]) {
        [_delegate getIt];
    }
}

- (void)changeQuestionBtnOnClick:(UIButton *)btn
{
    if (_delegate && [_delegate respondsToSelector:@selector(questionsFooterView:didClickOptionButton:)]) {
        [_delegate questionsFooterView:self didClickOptionButton:btn.tag == 501];
    }
}

@end
